<?
ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE);


include("../Class_1/dbcontroller.inc.php");
include("../Class_1/constants.inc.php");

$db = new DBController(MYHOST,MYUSER,MYPASSWORD,MYDB);
$db_ora = new DBController_ora($_SESSION['User'],$_SESSION['Password'],MYDB_ora);


class iTable{

var $tbl_name;
//var $array_field;		MIGHT BE USED IN FUTURE




function __construct($pName){
	$this->tbl_name=$pName;
	//$this->array_field=$pFields; 		MIGHT BE USED IN FUTURE
}

function showInfo(){
	echo "Table Name ".$this->tbl_name."<br/>";
	print_r($this->array_field);

}

function insertRecord($pField,$pValue){

	$sql = "";

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	
	$sql = "INSERT INTO ".$this->tbl_name." (";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,

	$sql .= ") VALUES (";
	
	for($k=0; $k<count($tmpValue); $k++){
	
		$sql .= $tmpValue[$k].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= ")";
	
	//echo $sql;
	//exit;
	
	$this->ExeSQL($sql);
	

}


function deleteRecord($pField,$pValue){

	$sql = "";
	
	$sql = "DELETE FROM ".$this->tbl_name." WHERE ".$pField." = ".$pValue;

	//echo $sql;
	
	$this->ExeSQL($sql);
}


function updateRecord($pField,$pValue,$pKey,$pKeyVal){

	$sql = "";

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	$tmpKey=explode(";",$pKey);
	$tmpKeyVal=explode(";",$pKeyVal);
	
	$sql = "UPDATE ".$this->tbl_name." SET ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i]." = ".$tmpValue[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,

	$sql .= " WHERE ";
	
	for($i=0; $i<count($tmpKey); $i++){
	
		$sql .= $tmpKey[$i]." = ".$tmpKeyVal[$i]." AND ";
	
	}
	
	$sql = substr($sql, 0, -5);			//CLIPPING THE LAST ' AND '
	
	//echo $sql;
	//exit;
	
	$this->ExeSQL($sql);
	

}


function getResult_SQL($pSQL){
global $db;

if($db->connect()){
	//echo 'Connected';
	
		if($db->executeQuery($pSQL)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db->get_err_msg();
	}
	
	    return $db->loadResult();




}

function getResult($pField,$pKey,$pKeyVal){

global $db;

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	$tmpKey=explode(";",$pKey);
	$tmpKeyVal=explode(";",$pKeyVal);

	
	$sql = "SELECT ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= " FROM ".$this->tbl_name." WHERE ";
	
	for($i=0; $i<count($tmpKey); $i++){
	
		$sql .= $tmpKey[$i]." = ".$tmpKeyVal[$i]." AND ";
	
	}
	
	$sql = substr($sql, 0, -5);			//CLIPPING THE LAST ' AND '
	
	//echo $sql.'<br/>';
	//exit;
	
if($db->connect()){
	//echo 'Connected';
	
		if($db->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db->get_err_msg();
	}
	
	    return $db->loadResult();

}


function getNumRows($pField,$pKey,$pKeyVal){

global $db;

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	
	$sql = "SELECT ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= " FROM ".$this->tbl_name." WHERE ".$pKey." = ".$pKeyVal;
	
	
	echo $sql;
	
if($db->connect()){
	//echo 'Connected';
	
		if($db->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db->get_err_msg();
	}
	
	    return $db->getSelectedRows();

}


function ExeSQL($sql){
global $db;

if($db->connect()){
	//echo 'Connected';
	
		if($db->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db->get_err_msg();
	}
	
	    //return $db->loadResult();
}

function close_connection(){
	global $db;
	
	$db->close_conn();
	
	}



}	//End of class iTable


class iTable_ora{

var $tbl_name;
//var $array_field;		MIGHT BE USED IN FUTURE

function __construct($pName){
	$this->tbl_name=$pName;
	//$this->array_field=$pFields; 		MIGHT BE USED IN FUTURE
}

function showInfo(){
	echo "Table Name ".$this->tbl_name."<br/>";
	print_r($this->array_field);

}

function insertRecord($pField,$pValue){

	$sql = "";

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	
	$sql = "INSERT INTO ".$this->tbl_name." (";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,

	$sql .= ") VALUES (";
	
	for($k=0; $k<count($tmpValue); $k++){
	
		$sql .= $tmpValue[$k].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= ")";
	
	//echo $sql;
	//exit;
	
	$this->ExeSQL($sql);
	

}


function deleteRecord($pField,$pValue){

	$sql = "";
	
	$sql = "DELETE FROM ".$this->tbl_name." WHERE ".$pField." = ".$pValue;

	//echo $sql;
	
	$this->ExeSQL($sql);
}


function updateRecord($pField,$pValue,$pKey,$pKeyVal){

	$sql = "";

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	$tmpKey=explode(";",$pKey);
	$tmpKeyVal=explode(";",$pKeyVal);
	
	$sql = "UPDATE ".$this->tbl_name." SET ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i]." = ".$tmpValue[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,

	$sql .= " WHERE ";
	
	for($i=0; $i<count($tmpKey); $i++){
	
		$sql .= $tmpKey[$i]." = ".$tmpKeyVal[$i]." AND ";
	
	}
	
	$sql = substr($sql, 0, -5);			//CLIPPING THE LAST ' AND '
	
	//echo $sql;
	//exit;
	
	$this->ExeSQL($sql);
	

}


function getResult_SQL($pSQL){
global $db_ora;

if($db_ora->connect()){
	//echo 'Connected';
	
		if($db_ora->executeQuery($pSQL)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db_ora->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db_ora->get_err_msg();
	}
	
	    return $db_ora->loadResult();




}

function getResult($pField,$pKey,$pKeyVal){

global $db_ora;

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	$tmpKey=explode(";",$pKey);
	$tmpKeyVal=explode(";",$pKeyVal);

	
	$sql = "SELECT ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= " FROM ".$this->tbl_name." WHERE ";
	
	for($i=0; $i<count($tmpKey); $i++){
	
		$sql .= $tmpKey[$i]." = ".$tmpKeyVal[$i]." AND ";
	
	}
	
	$sql = substr($sql, 0, -5);			//CLIPPING THE LAST ' AND '
	
	//echo $sql.'<br/>';
	//exit;
	
if($db_ora->connect()){
	//echo 'Connected';
	
		if($db_ora->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db_ora->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db_ora->get_err_msg();
	}
	
	
	$arr = $db_ora->loadResult();
	
	//print_r($arr);
	//exit;
	
	return $arr;

}


function getNumRows($pField,$pKey,$pKeyVal){

global $db_ora;

	$tmpField=explode(";",$pField);
	$tmpValue=explode(";",$pValue);
	
	$sql = "SELECT ";
	
	for($i=0; $i<count($tmpField); $i++){
	
		$sql .= $tmpField[$i].",";
	
	}
	
	$sql = substr($sql, 0, -1);			//CLIPPING THE LAST ,
	
	$sql .= " FROM ".$this->tbl_name." WHERE ".$pKey." = ".$pKeyVal;
	
	
	echo $sql;
	
if($db_ora->connect()){
	//echo 'Connected';
	
		if($db_ora->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db_ora->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db_ora->get_err_msg();
	}
	
	    return $db_ora->getSelectedRows();

}


function ExeSQL($sql){
global $db_ora;

if($db_ora->connect()){
	//echo 'Connected';
	
		if($db_ora->executeQuery($sql)){
			//echo 'Executed';
		}else{
			echo "Execution Error says: ".$db_ora->get_err_msg();
		}
	}else{
		echo "Connection Error says: ".$db_ora->get_err_msg();
	}
	
	    //return $db_ora->loadResult();
}

function close_connection(){
	global $db_ora;
	
	$db_ora->close_conn();
	
	}



}	//End of class iTable


function sendMail($pCaption,$pValue,$pTo,$pFrom,$pSubject,$pMsgHeader,$pMsgBody){

$to = $pTo;
$from = $pFrom;
$subject = pSubject;

    $tmpCaption=explode(";",$pCaption);
    $tmpValue=explode(";",$pValue);
    
    $message =
'<html>
<head>
<title>iTable</title>
</head>
<body>
<table width="546" cellspacing="0" bgcolor="#FBFAF4">
  <tr>
    <td colspan="2" align="left" bgcolor="#ECE9D8"><strong class="headbrown">'.$pMsgHeader.'</strong></td>
  </tr>
  <tr>
    <td>'.$pMsgBody.'</td>
  </tr>
  <tr><td><table cellspacing="0" bgcolor="#FBFAF4" style="padding:10px 0 0 15px;">';
 
  for($i=0; $i<count($tmpCaption); $i++){
  $message .=
   '<tr>
    <td class="head"><strong>'.$tmpCaption[$i].'</strong></td>
    <td >&nbsp;&nbsp;&nbsp;</td>
    <td align="left">'.$tmpValue[$i].'</td>
  </tr>';
  }  
 
  $message .=
 '</td></tr></table></table>
  </body>
        </html>';
    
        
		//echo $message;
		//exit;
		
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
        
        /* additional headers */
        
        $headers .= "From: $from\r\n";
        
        /* and now mail it */
         if(mail($to,  $subject, $message, $headers)){
             echo "Your Request Has Been Posted Successfully. ".$to;
        }else{
            echo "message cannot be delivered! email is: ".$email;
        }
}



?>